import { formatTime } from '../../utils/date'

export default {
  clip(val: any, limit = 5) {
    val += ''
    if (!val) return ''
    return val.length > limit ? `${val.slice(0, limit)}...` : val
  },
  hiddenMobile(val: string | number, start: number, hidden: number) {
    // 从第几位起隐藏几位数 ，默认手机号规则隐藏中间4位
    if (!val) return ''
    val = String(val)
    const end = start + hidden
    const end2 = val.length - end < 0 ? 0 : val.length - end
    return (
      val.substring(0, start)
      + '*'.repeat(hidden)
      + val.substring(end, end + end2)
    )
  },
  format(timeStamp: any, format = 'Y-m-d H:i') {
    if (!timeStamp) return ''
    return formatTime(timeStamp, format)
  }
}
